home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr36 / putt100.zip / JAMUTILW.ZIP / JAMUTILW.C < prev    next >
C/C++ Source or Header  |  1993-07-01  |  29KB  |  1,044 lines

  1. /*
  2. **  JAM(mbp) - The Joaquim-Andrew-Mats Message Base Proposal
  3. **
  4. **  JAM Windows Utility
  5. **
  6. **  Written by Mats Wallin
  7. **
  8. **  ----------------------------------------------------------------------
  9. **
  10. **  jamutilw.c (JAMmb)
  11. **
  12. **  JAM Windows Utility, display contents of a JAM messagebase
  13. **
  14. **  Copyright 1993 Joaquim Homrighausen, Andrew Milner, Mats Birch, and
  15. **  Mats Wallin. ALL RIGHTS RESERVED.
  16. **
  17. **  93-06-28    MW
  18. **  Initial coding
  19. */
  20.  
  21. #define STRICT
  22.  
  23. #include <windows.h>
  24. #include <commdlg.h>
  25.  
  26. #include <stdarg.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29.  
  30. #include "jammb.h"
  31.  
  32. #include "jamutilw.h"
  33. #include "dlgutilw.h"
  34.  
  35.  
  36. #define MSGBOXTITLE       "JAM(mb) Windows Utility"
  37.  
  38. #if defined (__BORLANDC__)
  39. #pragma warn -par
  40. #endif
  41.  
  42. /*
  43. **  Local variables
  44. */
  45.  
  46. static HWND       hMainWnd;
  47. static HINSTANCE  hInstance;
  48.  
  49. static UINT32     MsgNo;
  50.  
  51. /*
  52. **  Prototypes
  53. */
  54.  
  55. int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow );
  56. int InitApplication( HINSTANCE hinstCurrent );
  57. int InitInstance( HINSTANCE hinstCurrent, int nCmdShow );
  58. LRESULT CALLBACK WndProcJamUtil( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
  59. BOOL CALLBACK DlgProcMsgHdr( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  60. BOOL CALLBACK DlgProcSubFields( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  61. BOOL CALLBACK DlgProcMsgText( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  62. BOOL CALLBACK DlgProcHdrInfo( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  63. BOOL CALLBACK DlgProcGotoMsg( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  64. int OpenJAMbase( void );
  65. int DisplayMsgHdr( HWND hDlg, UINT32 MsgNo );
  66. int DisplayHdrInfo( HWND hDlg );
  67. int DisplaySubfields( HWND hDlg, UINT32 MsgNo );
  68. int DisplayMsgTxt( HWND hDlg, UINT32 MsgNo );
  69. int cdecl DlgItemPrintf( HWND hDlg, int Id, LPSTR Fmt, ... );
  70. LPSTR DispTime( UINT32 * pt );
  71. LPSTR AttrToStr( UINT32 Attr );
  72. LPSTR GetSubFldName( JAMSUBFIELD FAR * pSubFld );
  73. LPSTR GetSubFldStr( JAMSUBFIELD FAR * pSubFld );
  74.  
  75.  
  76. /* ---------------------------------------------------------------------- *
  77.  *
  78.  *  WinMain
  79.  *
  80.  * ---------------------------------------------------------------------- */
  81.  
  82. int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow )
  83. {
  84.   MSG   msg;
  85.  
  86.   if( hinstPrevious == NULL )
  87.     if( !InitApplication( hinstCurrent ))
  88.       return( FALSE );
  89.  
  90.   if( !InitInstance( hinstCurrent, nCmdShow ))
  91.     return( FALSE );
  92.  
  93.   while( GetMessage( &msg, NULL, 0, 0 ))
  94.     {
  95.     TranslateMessage( &msg );
  96.     DispatchMessage( &msg );
  97.     }
  98.  
  99.   return(( int ) msg.wParam );
  100. }
  101.  
  102.  
  103. /* ---------------------------------------------------------------------- *
  104.  *
  105.  *  InitApplication
  106.  *
  107.  * ---------------------------------------------------------------------- */
  108.  
  109. int InitApplication( HINSTANCE hinstCurrent )
  110. {
  111.   WNDCLASS    WndClass;
  112.  
  113.   memset( &WndClass, '\0', sizeof( WndClass ));
  114.  
  115.   WndClass.style          = 0;
  116.   WndClass.lpfnWndProc    = WndProcJamUtil;
  117.   WndClass.cbClsExtra     = 0;
  118.   WndClass.cbWndExtra     = 0;
  119.   WndClass.hInstance      = hinstCurrent;
  120.   WndClass.hIcon          = LoadIcon( hinstCurrent, MAKEINTRESOURCE( IDI_JAMUTILW ));
  121.   WndClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  122.   WndClass.hbrBackground  = ( HBRUSH ) ( COLOR_BACKGROUND + 1 );
  123.   WndClass.lpszMenuName   = NULL;
  124.   WndClass.lpszClassName  = "JAMUTILW";
  125.  
  126.   if( RegisterClass( &WndClass ) == NULL )
  127.     return( FALSE );
  128.  
  129.   return( TRUE );
  130. }
  131.  
  132.  
  133. /* ---------------------------------------------------------------------- *
  134.  *
  135.  *  InitInstance
  136.  *
  137.  * ---------------------------------------------------------------------- */
  138.  
  139. int InitInstance( HINSTANCE hinstCurrent, int nCmdShow )
  140. {
  141.   hInstance = hinstCurrent;
  142.  
  143.  
  144.   hMainWnd = CreateWindow(  "JAMUTILW",
  145.                             MSGBOXTITLE,
  146.                             WS_OVERLAPPEDWINDOW | WS_MINIMIZE | WS_VISIBLE,
  147.                             CW_USEDEFAULT,
  148.                             CW_USEDEFAULT,
  149.                             CW_USEDEFAULT,
  150.                             CW_USEDEFAULT,
  151.                             HWND_DESKTOP,
  152.                             NULL,
  153.                             hInstance,
  154.                             NULL );
  155.  
  156.   if( hMainWnd == NULL )
  157.     {
  158.     MessageBox( NULL, "Unable to create main window", MSGBOXTITLE, MB_OK );
  159.     return( FALSE );
  160.     }
  161.  
  162.   PostMessage( hMainWnd, WM_COMMAND, IDM_FILE_OPEN, 0L );
  163.  
  164.   return( TRUE );
  165. }
  166.  
  167.  
  168. /* ---------------------------------------------------------------------- *
  169.  *
  170.  *  WndProcJamUtil
  171.  *
  172.  * ---------------------------------------------------------------------- */
  173.  
  174. LRESULT CALLBACK WndProcJamUtil( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  175. {
  176.   DLGPROC   pDlgProcMsgHdr;
  177.   int       stat;
  178.  
  179.   switch( msg )
  180.     {
  181.     case WM_COMMAND :
  182.       switch( wParam )
  183.         {
  184.         case IDM_FILE_OPEN :
  185.           if(( stat = OpenJAMbase( )) == 0 )
  186.             {
  187.             PostMessage( hMainWnd, WM_CLOSE, 0, 0L );
  188.             }
  189.           else if( stat > 0 )
  190.             {
  191.             if(( pDlgProcMsgHdr = ( DLGPROC ) MakeProcInstance(( FARPROC ) DlgProcMsgHdr, hInstance )) != NULL )
  192.               {
  193.               DialogBox( hInstance, "MSGHDR", hMainWnd, pDlgProcMsgHdr );
  194.               FreeProcInstance(( FARPROC ) pDlgProcMsgHdr );
  195.               }
  196.             }
  197.  
  198.           JAMsysDeinitApiRec( &JamRec );
  199.           PostMessage( hMainWnd, WM_COMMAND, IDM_FILE_OPEN, 0L );
  200.           break;
  201.         }
  202.       break;
  203.     case WM_DESTROY:
  204.       PostQuitMessage(0);
  205.       return (0);
  206.     }
  207.  
  208.   return( DefWindowProc( hWnd, msg, wParam, lParam ));
  209. }
  210.  
  211.  
  212. /* ---------------------------------------------------------------------- *
  213.  *
  214.  *  DlgProcMsgHdr
  215.  *
  216.  * ---------------------------------------------------------------------- */
  217.  
  218. BOOL CALLBACK DlgProcMsgHdr( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  219. {
  220.   char            Buf [128];
  221.   DLGPROC         pDlgProc;
  222.   RECT            rect;
  223.   int             Width,
  224.                   Height;
  225.   HMENU           hMenu;
  226.  
  227.   switch( msg )
  228.     {
  229.     case WM_INITDIALOG :
  230.       wsprintf( Buf, "Message Header: %s", ( LPSTR ) JamRec.BaseName );
  231.       SetWindowText( hDlg, Buf );
  232. /*
  233. **  Add a About... menu item
  234. */
  235.       if(( hMenu = GetSystemMenu( hDlg, FALSE )) != NULL )
  236.         {
  237.         AppendMenu( hMenu, MF_SEPARATOR, 0, NULL );
  238.         AppendMenu( hMenu, MF_STRING, IDM_ABOUT, "&About..." );
  239.         }
  240. /*
  241. **  Center the dialog on the screen
  242. */
  243.       GetWindowRect( hDlg, &rect );
  244.       Width = GetSystemMetrics( SM_CXSCREEN );
  245.       Height = GetSystemMetrics( SM_CYSCREEN );
  246.       SetWindowPos( hDlg, NULL,
  247.                     ( Width - ( rect.right - rect.left )) / 2,
  248.                     ( Height - ( rect.bottom - rect.top )) / 2,
  249.                     0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
  250. /*
  251. **  Display the first message header
  252. */
  253.       MsgNo = JamRec.HdrInfo.BaseMsgNum;
  254.       if( !DisplayMsgHdr( hDlg, MsgNo ))
  255.         {
  256.         EndDialog( hDlg, FALSE );
  257.         return( FALSE );
  258.         }
  259.       return( TRUE );
  260.  
  261.     case WM_COMMAND :
  262.       switch( wParam )
  263.         {
  264.         case IDC_PREVIOUS :
  265.           if( !DisplayMsgHdr( hDlg, --MsgNo ))
  266.             MsgNo++;
  267.           break;
  268.  
  269.         case IDC_NEXT :
  270.           if( !DisplayMsgHdr( hDlg, ++MsgNo ))
  271.             MsgNo--;
  272.           break;
  273.  
  274.         case IDC_GOTO :
  275.           {
  276.           UINT32 OldMsgNo = MsgNo;
  277.  
  278.           if(( pDlgProc = ( DLGPROC ) MakeProcInstance(( FARPROC ) DlgProcGotoMsg, hInstance )) != NULL )
  279.             {
  280.             MsgNo = DialogBox( hInstance, "GOTOMSG", hDlg, pDlgProc );
  281.             FreeProcInstance(( FARPROC ) pDlgProc );
  282.             }
  283.           if( MsgNo == 0 || !DisplayMsgHdr( hDlg, MsgNo ))
  284.             MsgNo = OldMsgNo;
  285.           break;
  286.           }
  287.  
  288.         case IDC_FIELDS :
  289.           if(( pDlgProc = ( DLGPROC ) MakeProcInstance(( FARPROC ) DlgProcSubFields, hInstance )) != NULL )
  290.             {
  291.             DialogBox( hInstance, "SUBFIELDS", hDlg, pDlgProc );
  292.             FreeProcInstance(( FARPROC ) pDlgProc );
  293.             }
  294.           break;
  295.  
  296.         case IDC_TEXT :
  297.           if(( pDlgProc = ( DLGPROC ) MakeProcInstance(( FARPROC ) DlgProcMsgText, hInstance )) != NULL )
  298.             {
  299.             DialogBox( hInstance, "MSGTEXT", hDlg, pDlgProc );
  300.             FreeProcInstance(( FARPROC ) pDlgProc );
  301.             }
  302.           break;
  303.  
  304.         case IDC_HDRINFO :
  305.           if(( pDlgProc = ( DLGPROC ) MakeProcInstance(( FARPROC ) DlgProcHdrInfo, hInstance )) != NULL )
  306.             {
  307.             DialogBox( hInstance, "HDRINFO", hDlg, pDlgProc );
  308.             FreeProcInstance(( FARPROC ) pDlgProc );
  309.             }
  310.           break;
  311.  
  312.         case IDC_EXIT :
  313.         case IDCANCEL :
  314.           EndDialog( hDlg, TRUE );
  315.           return( TRUE );
  316.         }
  317.       break;
  318.  
  319.     case WM_SYSCOMMAND :
  320.       switch( wParam & 0xFFF0 )
  321.         {
  322.         case IDM_ABOUT :
  323.           MessageBox( hDlg, "JAM(mb) Windows Utility\n"
  324.                             "\n"
  325.                             "⌐ 1993\tJoaquim Homrighausen\n"
  326.                             "\tAndrew Milner\n"
  327.                             "\tMats Birch\n\tMats Wallin\n\n"
  328.                             "ALL RIGHTS RESERVED.\n"
  329.                             "\n"
  330.                             "Written by Mats Wallin",
  331.                             MSGBOXTITLE,
  332.                             MB_OK|MB_ICONINFORMATION );
  333.           break;
  334.         }
  335.       break;
  336.     }
  337.  
  338.   return( FALSE );
  339. }
  340.  
  341.  
  342. /* ---------------------------------------------------------------------- *
  343.  *
  344.  *  DlgProcSubFields
  345.  *
  346.  * ---------------------------------------------------------------------- */
  347.  
  348. BOOL CALLBACK DlgProcSubFields( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  349. {
  350.   static int  TabStops [4] = {20, 44, 100, 128};
  351.   char        Buf [128];
  352.  
  353.   switch( msg )
  354.     {
  355.     case WM_INITDIALOG :
  356.       SendDlgItemMessage( hDlg, IDC_FLD_LISTBOX, LB_SETTABSTOPS,
  357.                         sizeof( TabStops ) / sizeof( TabStops [0] ),
  358.                         ( LPARAM ) ( int FAR * ) TabStops );
  359.  
  360.       wsprintf( Buf, "Message SubFields: %s", ( LPSTR ) JamRec.BaseName );
  361.       SetWindowText( hDlg, Buf );
  362.       DisplaySubfields( hDlg, MsgNo );
  363.       return( TRUE );
  364.  
  365.     case WM_COMMAND :
  366.       switch( wParam )
  367.         {
  368.         case IDOK :
  369.         case IDCANCEL :
  370.           EndDialog( hDlg, wParam == IDOK );
  371.           break;
  372.         }
  373.     }
  374.  
  375.   return( FALSE );
  376. }
  377.  
  378. /* ---------------------------------------------------------------------- *
  379.  *
  380.  *  DlgProcMsgText
  381.  *
  382.  * ---------------------------------------------------------------------- */
  383.  
  384. BOOL CALLBACK DlgProcMsgText( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  385. {
  386.   char    Buf [128];
  387.  
  388.   switch( msg )
  389.     {
  390.     case WM_INITDIALOG :
  391.       wsprintf( Buf, "Message Text: %s", ( LPSTR ) JamRec.BaseName );
  392.       SetWindowText( hDlg, Buf );
  393.       DisplayMsgTxt( hDlg, MsgNo );
  394.       return( TRUE );
  395.  
  396.     case WM_COMMAND :
  397.       switch( wParam )
  398.         {
  399.         case IDOK :
  400.         case IDCANCEL :
  401.           EndDialog( hDlg, wParam == IDOK );
  402.           break;
  403.         }
  404.     }
  405.  
  406.   return( FALSE );
  407. }
  408.  
  409.  
  410. /* ---------------------------------------------------------------------- *
  411.  *
  412.  *  DlgProcHdrInfo
  413.  *
  414.  * ---------------------------------------------------------------------- */
  415.  
  416. BOOL CALLBACK DlgProcHdrInfo( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  417. {
  418.   char    Buf [128];
  419.  
  420.   switch( msg )
  421.     {
  422.     case WM_INITDIALOG :
  423.       wsprintf( Buf, "Header Info: %s", ( LPSTR ) JamRec.BaseName );
  424.       SetWindowText( hDlg, Buf );
  425.  
  426.       DisplayHdrInfo( hDlg );
  427.       return( TRUE );
  428.  
  429.     case WM_COMMAND :
  430.       switch( wParam )
  431.         {
  432.         case IDOK :
  433.           EndDialog( hDlg, TRUE );
  434.           return( TRUE );
  435.  
  436.         case IDCANCEL :
  437.           EndDialog( hDlg, FALSE );
  438.           return( TRUE );
  439.         }
  440.     }
  441.  
  442.   return( FALSE );
  443. }
  444.  
  445.  
  446. /* ---------------------------------------------------------------------- *
  447.  *
  448.  *  DlgProcGotoMsg
  449.  *
  450.  * ---------------------------------------------------------------------- */
  451.  
  452. BOOL CALLBACK DlgProcGotoMsg( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  453. {
  454.   char    Buf [16];
  455.  
  456.   switch( msg )
  457.     {
  458.     case WM_COMMAND :
  459.       switch( wParam )
  460.         {
  461.         case IDOK :
  462.           SendDlgItemMessage( hDlg, IDC_MSGNO, WM_GETTEXT, sizeof( Buf ), ( LPARAM ) ( LPSTR ) Buf );
  463.           EndDialog( hDlg, atoi( Buf ));
  464.           return( TRUE );
  465.  
  466.         case IDCANCEL :
  467.           EndDialog( hDlg, 0 );
  468.           return( TRUE );
  469.         }
  470.     }
  471.  
  472.   return( FALSE );
  473. }
  474.  
  475.  
  476. /* ---------------------------------------------------------------------- *
  477.  *
  478.  *  OpenJAMbase
  479.  *
  480.  * ---------------------------------------------------------------------- */
  481.  
  482. int OpenJAMbase( void )
  483. {
  484.   static char     InitialDir [128] = "";
  485.   OPENFILENAME    ofn;
  486.   char            FileName [128];
  487.   char            FilterStr [128];
  488.   int             Len,
  489.                   i;
  490.   char            ch;
  491.  
  492.   memset( &ofn, '\0', sizeof( ofn ));
  493.   FileName [0] = '\0';
  494.  
  495.   Len = LoadString( hInstance, IDS_FILTERS, FilterStr, sizeof( FilterStr ));
  496.   ch = FilterStr [Len - 1];
  497.   for( i = 0; i < Len; i++ )
  498.     if( FilterStr [i] == ch )
  499.       FilterStr [i] = '\0';
  500.  
  501.   ofn.lStructSize       = sizeof( ofn );
  502.   ofn.hwndOwner         = hMainWnd;
  503.   ofn.hInstance         = hInstance;
  504.   ofn.lpstrFilter       = FilterStr;
  505.   ofn.lpstrCustomFilter = NULL;
  506.   ofn.nMaxCustFilter    = 0;
  507.   ofn.nFilterIndex      = 1;
  508.   ofn.lpstrFile         = FileName;
  509.   ofn.nMaxFile          = sizeof( FileName );
  510.   ofn.lpstrFileTitle    = NULL;
  511.   ofn.nMaxFileTitle     = 0;
  512.   ofn.lpstrInitialDir   = InitialDir;
  513.   ofn.lpstrTitle        = NULL;
  514.   ofn.Flags             = OFN_FILEMUSTEXIST|
  515.                           OFN_HIDEREADONLY;
  516.   ofn.nFileOffset       = 0;
  517.   ofn.nFileExtension    = 0;
  518.   ofn.lpstrDefExt       = "JHR";
  519.   ofn.lCustData         = 0;
  520.   ofn.lpfnHook          = NULL;
  521.   ofn.lpTemplateName    = NULL;
  522.  
  523.   do
  524.     {
  525.     if( !GetOpenFileName( &ofn ))
  526.       return( FALSE );
  527.  
  528.     if( ofn.nFileOffset )
  529.       memcpy( InitialDir, FileName, ofn.nFileOffset );
  530.     InitialDir [ofn.nFileOffset] = '\0';
  531.  
  532.     if( ofn.Flags & OFN_EXTENSIONDIFFERENT )
  533.       MessageBox( hMainWnd, "Invalid extension choosen", MSGBOXTITLE, MB_OK );
  534.     }
  535.   while( ofn.Flags & OFN_EXTENSIONDIFFERENT );
  536.  
  537.   FileName [ofn.nFileExtension - 1] = '\0';
  538.  
  539.  
  540. /*
  541. **  Open the specified JAM messagebase
  542. */
  543.  
  544.   if( !JAMsysInitApiRec( &JamRec, FileName, WORKBUFSIZE ))
  545.     {
  546.     MessageBox( hMainWnd, "Unable to initialize APIREC structure", MSGBOXTITLE, MB_OK );
  547.     return( -1 );
  548.     }
  549.  
  550.   if( !JAMmbOpen( &JamRec ))
  551.     {
  552.     MessageBox( hMainWnd, "Unable to open specified JAM messagebase", MSGBOXTITLE, MB_OK );
  553.     return( -1 );
  554.     }
  555.  
  556.   return( TRUE );
  557. }
  558.  
  559.  
  560. /* ---------------------------------------------------------------------- *
  561.  *
  562.  *  DisplayMsgHdr
  563.  *
  564.  * ---------------------------------------------------------------------- */
  565.  
  566. int DisplayMsgHdr( HWND hDlg, UINT32 MsgNo )
  567. {
  568.   UINT32    TotalMsgs;
  569.  
  570.   if( MsgNo < JamRec.HdrInfo.BaseMsgNum )
  571.     {
  572.     char    Buf [128];
  573.  
  574.     wsprintf( Buf, "Invalid message number: %lu", MsgNo );
  575.     MessageBox( hDlg, Buf, MSGBOXTITLE, MB_OK );
  576.     return( FALSE );
  577.     }
  578.  
  579.   TotalMsgs = _llseek( JamRec.IdxHandle, 0L, 2 ) / sizeof( JAMIDXREC );
  580.  
  581.   if(( MsgNo - JamRec.HdrInfo.BaseMsgNum ) >= TotalMsgs )
  582.     {
  583.     MessageBox( hDlg, "No more messages", MSGBOXTITLE, MB_OK );
  584.     return( FALSE );
  585.     }
  586.  
  587.   if( !JAMmbFetchMsgHdr( &JamRec, MsgNo, 0 ))
  588.     {
  589.     char    Buf [128];
  590.  
  591.     wsprintf( Buf, "Error reading message header, code: %d, errno: %d", JamRec.APImsg, JamRec.Errno );
  592.     MessageBox( hDlg, Buf, MSGBOXTITLE, MB_OK );
  593.     return( FALSE );
  594.     }
  595.  
  596.   DlgItemPrintf( hDlg, IDC_MSGNUMBER,         "%lu", MsgNo );
  597.   DlgItemPrintf( hDlg, IDC_TOTALMSGS,         "%lu", TotalMsgs );
  598.   DlgItemPrintf( hDlg, IDC_HDR_SIGNATURE,     "<%02x><%02x><%02x><%02x>",
  599.                                               JamRec.Hdr.Signature [0],
  600.                                               JamRec.Hdr.Signature [1],
  601.                                               JamRec.Hdr.Signature [2],
  602.                                               JamRec.Hdr.Signature [3] );
  603.   DlgItemPrintf( hDlg, IDC_HDR_REVISION,      "%04x", JamRec.Hdr.Revision );
  604.   DlgItemPrintf( hDlg, IDC_HDR_SUBFLDLEN,     "%lu", JamRec.Hdr.SubfieldLen );
  605.   DlgItemPrintf( hDlg, IDC_HDR_TIMESREAD,     "%lu", JamRec.Hdr.TimesRead );
  606.   DlgItemPrintf( hDlg, IDC_HDR_MSGIDCRC,      "%08lx", JamRec.Hdr.MsgIdCRC );
  607.   DlgItemPrintf( hDlg, IDC_HDR_REPLYCRC,      "%08lx", JamRec.Hdr.ReplyCRC );
  608.   DlgItemPrintf( hDlg, IDC_HDR_REPLYTO,       "%lu", JamRec.Hdr.ReplyTo );
  609.   DlgItemPrintf( hDlg, IDC_HDR_REPLY1ST,      "%lu", JamRec.Hdr.Reply1st );
  610.   DlgItemPrintf( hDlg, IDC_HDR_REPLYNEXT,     "%lu", JamRec.Hdr.ReplyNext );
  611.   DlgItemPrintf( hDlg, IDC_HDR_DATEWRITTEN,   "%s", DispTime( &JamRec.Hdr.DateWritten ));
  612.   DlgItemPrintf( hDlg, IDC_HDR_DATERECEIVED,  "%s", DispTime( &JamRec.Hdr.DateReceived ));
  613.   DlgItemPrintf( hDlg, IDC_HDR_DATEPROCESSED, "%s", DispTime( &JamRec.Hdr.DateProcessed ));
  614.   DlgItemPrintf( hDlg, IDC_HDR_MSGNUM,        "%lu", JamRec.Hdr.MsgNum );
  615.   DlgItemPrintf( hDlg, IDC_HDR_ATTRIBUTE,     "%s", AttrToStr( JamRec.Hdr.Attribute ));
  616.   DlgItemPrintf( hDlg, IDC_HDR_ATTRIBUTE2,    "%lu", JamRec.Hdr.Attribute2 );
  617.   DlgItemPrintf( hDlg, IDC_HDR_TXTOFFSET,     "%lu", JamRec.Hdr.TxtOffset );
  618.   DlgItemPrintf( hDlg, IDC_HDR_TXTLEN,        "%lu", JamRec.Hdr.TxtLen );
  619.   DlgItemPrintf( hDlg, IDC_HDR_PASSWORDCRC,   "%08lx", JamRec.Hdr.PasswordCRC );
  620.   DlgItemPrintf( hDlg, IDC_HDR_COST,          "%u", JamRec.Hdr.Cost );
  621.  
  622.   return( TRUE );
  623. }
  624.  
  625.  
  626. /* ---------------------------------------------------------------------- *
  627.  *
  628.  *  DisplayHdrInfo
  629.  *
  630.  * ---------------------------------------------------------------------- */
  631.  
  632. int DisplayHdrInfo( HWND hDlg )
  633. {
  634.   UINT32    TotalMsgs;
  635.  
  636. /*
  637. **  Read the header information record
  638. */
  639.  
  640.   if( !JAMmbUpdateHeaderInfo( &JamRec, 0 ))
  641.     {
  642.     char    Buf [128];
  643.  
  644.     wsprintf( Buf, "Error reading header info, code: %d, errno: %d\n", JamRec.APImsg, JamRec.Errno );
  645.     MessageBox( hDlg, Buf, MSGBOXTITLE, MB_OK );
  646.     return( FALSE );
  647.     }
  648.  
  649.  
  650. /*
  651. **  Calculate the total (active + deleted) number of messages
  652. */
  653.  
  654.   TotalMsgs = _llseek( JamRec.IdxHandle, 0L, 2 ) / sizeof( JAMIDXREC );
  655.  
  656.  
  657. /*
  658. **  Display the information
  659. */
  660.  
  661.   DlgItemPrintf( hDlg, IDC_HDRINFO_SIGNATURE, "<%02x><%02x><%02x><%02x>",
  662.                                               JamRec.HdrInfo.Signature [0],
  663.                                               JamRec.HdrInfo.Signature [1],
  664.                                               JamRec.HdrInfo.Signature [2],
  665.                                               JamRec.HdrInfo.Signature [3] );
  666.  
  667.  
  668.   DlgItemPrintf( hDlg, IDC_HDRINFO_DATECREATED, "%s", DispTime( &JamRec.HdrInfo.DateCreated ));
  669.   DlgItemPrintf( hDlg, IDC_HDRINFO_MODCOUNTER,  "%lu", JamRec.HdrInfo.ModCounter );
  670.   DlgItemPrintf( hDlg ,IDC_HDRINFO_ACTIVEMSGS,  "%lu", JamRec.HdrInfo.ActiveMsgs );
  671.   DlgItemPrintf( hDlg, IDC_HDRINFO_PASSWORDCRC, "%08lx", JamRec.HdrInfo.PasswordCRC );
  672.   DlgItemPrintf( hDlg, IDC_HDRINFO_BASEMSGNUM,  "%lu", JamRec.HdrInfo.BaseMsgNum );
  673.   DlgItemPrintf( hDlg, IDC_HDRINFO_TOTALMSGS,   "%lu", TotalMsgs );
  674.   DlgItemPrintf( hDlg, IDC_HDRINFO_DELETEDMSGS, "%lu", TotalMsgs - JamRec.HdrInfo.ActiveMsgs );
  675.  
  676.   return( TRUE );
  677. }
  678.  
  679.  
  680. /* ---------------------------------------------------------------------- *
  681.  *
  682.  *  DisplaySubfields
  683.  *
  684.  * ---------------------------------------------------------------------- */
  685.  
  686. int DisplaySubfields( HWND hDlg, UINT32 MsgNo )
  687. {
  688.   UINT32  SubFldLen = JamRec.Hdr.SubfieldLen,
  689.           Len;
  690.  
  691.  
  692. /*
  693. **  Read the message header (and subfields)
  694. */
  695.  
  696.   if( !JAMmbFetchMsgHdr( &JamRec, JamRec.Hdr.MsgNum, 1 ))
  697.     {
  698.     char    Buf [128];
  699.  
  700.     wsprintf( Buf, "Error reading message header, code: %d, errno: %d", JamRec.APImsg, JamRec.Errno );
  701.     MessageBox( hDlg, Buf, MSGBOXTITLE, MB_OK );
  702.     return( FALSE );
  703.     }
  704.  
  705.  
  706. /*
  707. **  If it wasn't possible to read all subfields into the buffer,
  708. **  only process those that fit into the buffer
  709. */
  710.  
  711.   if( SubFldLen > JamRec.WorkLen )
  712.     SubFldLen = JamRec.WorkLen;
  713.  
  714.  
  715. /*
  716. **  Display the ruler
  717. */
  718.  
  719.   SendDlgItemMessage( hDlg, IDC_FLD_LISTBOX, LB_ADDSTRING, 0,
  720.                       ( LPARAM ) ( LPCSTR ) "HiID\tLoID\tName\tLen\tData" );
  721.  
  722.  
  723. /*
  724. **  And then all subfields
  725. */
  726.  
  727.   for(  JamRec.SubFieldPtr = ( JAMSUBFIELD FAR * ) JamRec.WorkBuf;
  728.  
  729.         JamRec.SubFieldPtr->DatLen + sizeof( JAMBINSUBFIELD ) <= SubFldLen;
  730.  
  731.         Len = JAMsysAlign( JamRec.SubFieldPtr->DatLen + sizeof( JAMBINSUBFIELD )),
  732.         SubFldLen -= Len,
  733.         JamRec.SubFieldPtr = ( JAMSUBFIELD FAR * ) JAMsysAddFarPtr( JamRec.SubFieldPtr, Len ))
  734.     {
  735.     char    Buf [256];
  736.  
  737.     wsprintf( Buf, "%u\t%u\t%-14.14s\t%lu\t\"%s\"",
  738.                   JamRec.SubFieldPtr->HiID, JamRec.SubFieldPtr->LoID,
  739.                   ( LPSTR ) GetSubFldName( JamRec.SubFieldPtr ),
  740.                   JamRec.SubFieldPtr->DatLen,
  741.                   ( LPSTR ) GetSubFldStr( JamRec.SubFieldPtr ));
  742.  
  743.     SendDlgItemMessage( hDlg, IDC_FLD_LISTBOX, LB_ADDSTRING, 0,
  744.                       ( LPARAM ) ( LPCSTR ) Buf );
  745.     }
  746.  
  747.     return (TRUE);
  748.  
  749. }
  750.  
  751.  
  752. /* ---------------------------------------------------------------------- *
  753.  *
  754.  *  DisplayMsgTxt
  755.  *
  756.  * ---------------------------------------------------------------------- */
  757.  
  758. int DisplayMsgTxt( HWND hDlg, UINT32 MsgNo )
  759. {
  760.   int           First = 1,          /* Flag if this is the first read */
  761.                 Col = 0;
  762.   UINT32        Pos = 0;
  763.   HLOCAL        hMem;
  764.   UINT          Size,
  765.                 BufSize;
  766.   UCHAR8      * pBuf,
  767.               * pBufStart;
  768.   UCHAR8  FAR * p;
  769.  
  770.  
  771. /*
  772. **  Free the old edit control memory area
  773. */
  774.  
  775.   if(( hMem = ( HLOCAL ) SendDlgItemMessage( hDlg, IDC_TXT_EDIT, EM_GETHANDLE, 0, 0L )) == NULL )
  776.     {
  777.     char    Buf [128];
  778.  
  779.     wsprintf( Buf, "Unable to get handle of old edit control memory" );
  780.     MessageBox( hDlg, Buf, MSGBOXTITLE, MB_OK );
  781.     return( FALSE );
  782.     }
  783.  
  784.   LocalFree( hMem );
  785.  
  786.  
  787. /*
  788. **  Allocate a new area, where the message text can be stored
  789. */
  790.  
  791.   for(  BufSize = 0xF000;
  792.         BufSize > 0 && ( hMem = LocalAlloc( LHND, BufSize )) == NULL;
  793.         BufSize -= 0x1000 )
  794.     ;
  795.  
  796.  
  797. /*
  798. **  Fill this area with the messagetext
  799. */
  800.  
  801.   pBuf = pBufStart = LocalLock( hMem );
  802.   Size = 0;
  803.  
  804.   while( TRUE )
  805.     {
  806.     if( !JAMmbFetchMsgTxt( &JamRec, First ))
  807.       {
  808.       char      Buf [128];
  809.  
  810.       wsprintf( Buf, "Error reading message text, code: %d, errno: %d", JamRec.APImsg, JamRec.Errno );
  811.       MessageBox( hDlg, Buf, MSGBOXTITLE, MB_OK );
  812.       LocalFree( hMem );
  813.       return( FALSE );
  814.       }
  815.  
  816.     if( JamRec.APImsg == JAMAPIMSG_NOMORETEXT )
  817.       break;
  818.  
  819.     First = 0;
  820.  
  821.     for( p = ( UCHAR8 FAR * ) JamRec.WorkBuf; Pos < JamRec.WorkPos; Pos++, p++ )
  822.       {
  823.       if( Size + 7 >= BufSize )
  824.         break;
  825.  
  826.       if( *p == '\r' )
  827.         {
  828.         strcpy(( CHAR8 * ) pBuf, "<0d>\r\n" );
  829.         Size += 6;
  830.         pBuf += 6;
  831.         Col = 0;
  832.         }
  833.  
  834.       else if( *p < ' ' )
  835.         {
  836.         wsprintf(( CHAR8 * ) pBuf, "<%02x>", *p );
  837.         Size += 4;
  838.         pBuf += 4;
  839.         Col += 4;
  840.         }
  841.       else
  842.         {
  843.         if( Col > 70 && *p == ' ' )
  844.           {
  845.           *pBuf++ = '\r';
  846.           *pBuf++ = '\n';
  847.           Size += 2;
  848.           Col = 0;
  849.           }
  850.         else
  851.           {
  852.           *pBuf++ = *p;
  853.           Size++;
  854.           Col++;
  855.           }
  856.         }
  857.       }
  858.     }
  859.  
  860.   *pBuf = '\0';
  861.  
  862.   OemToAnsi(( LPSTR ) pBufStart, ( LPSTR ) pBufStart );
  863.   LocalUnlock( hMem );
  864.  
  865.   LocalReAlloc( hMem, Size + 1, 0 );
  866.  
  867.   SendDlgItemMessage( hDlg, IDC_TXT_EDIT, EM_SETHANDLE, ( WPARAM ) hMem, 0L );
  868.  
  869.  
  870.   return( TRUE );
  871. }
  872.  
  873.  
  874. /* ---------------------------------------------------------------------- *
  875.  *
  876.  *  DlgItemPrintf
  877.  *
  878.  * ---------------------------------------------------------------------- */
  879.  
  880. int cdecl DlgItemPrintf( HWND hDlg, int Id, LPSTR Fmt, ...)
  881. {
  882.   char      Buf [256];
  883.   int       Len;
  884.   va_list   argptr;
  885.  
  886.   va_start( argptr, Fmt );
  887.   Len = wvsprintf( Buf, Fmt, argptr );
  888.   va_end( argptr );
  889.  
  890.   SetDlgItemText( hDlg, Id, Buf );
  891.  
  892.   return( Len );
  893. }
  894.  
  895.  
  896. /* ---------------------------------------------------------------------- *
  897.  *
  898.  *  DispTime
  899.  *
  900.  *    Converts the specified time to a ASCII string
  901.  *
  902.  *    Parameters:   UINT32 * pt             - # of seconds since 1970
  903.  *
  904.  *    Returns:      LPSTR                   - Ptr to buffer containing
  905.  *                                            ASCII string
  906.  *
  907.  * ---------------------------------------------------------------------- */
  908.  
  909. LPSTR DispTime( UINT32 * pt )
  910. {
  911.   static CHAR8    MonthNames [12][4] = {"Jan","Feb","Mar","Apr","May","Jun",
  912.                                         "Jul","Aug","Sep","Oct","Nov","Dec"};
  913.   static CHAR8    Buffer [64];
  914.   JAMTMptr        ptm;
  915.  
  916.   if( *pt == 0L )
  917.     strcpy( Buffer, "<null>" );
  918.   else
  919.     {
  920.     ptm = JAMsysLocalTime( pt );
  921.     wsprintf( Buffer, "%s %d, %4d  %2d:%02d:%02d",
  922.           ( LPSTR ) MonthNames [ptm->tm_mon], ptm->tm_mday, ptm->tm_year + 1900,
  923.           ptm->tm_hour, ptm->tm_min, ptm->tm_sec );
  924.     }
  925.  
  926.   return( Buffer );
  927. }
  928.  
  929.  
  930. /* ---------------------------------------------------------------------- *
  931.  *
  932.  *  AttrToStr
  933.  *
  934.  *    Convert the Attribute field to a ASCIIZ string containing all the
  935.  *    attribute names
  936.  *
  937.  *    Parameters:   UINT32 Attr   - The attributes to convert
  938.  *
  939.  *    Returns:      LPSTR         - Ptr to buffer with attribute names
  940.  *
  941.  * ---------------------------------------------------------------------- */
  942.  
  943. LPSTR AttrToStr( UINT32 Attr )
  944. {
  945.   static CHAR8    Buf [256];
  946.   CHAR8         * p = Buf;
  947.   int             i;
  948.  
  949.   Buf [0] = '\0';
  950.  
  951.   for( i = 0; i < 32; i++ )
  952.     {
  953.     if( Attr & 0x00000001L )
  954.       {
  955.       if( p != Buf )
  956.         {
  957.         *p++ = ',';
  958.         *p++ = ' ';
  959.         }
  960.       strcpy( p, AttrName [i] );
  961.       p = strchr( p, '\0' );
  962.       }
  963.  
  964.     Attr >>= 1;
  965.     }
  966.  
  967.   return( Buf );
  968. }
  969.  
  970.  
  971. /* ---------------------------------------------------------------------- *
  972.  *
  973.  *  GetSubFldName
  974.  *
  975.  *    Get the name of the specified subfield
  976.  *
  977.  *    Parameters:   JAMSUBFIELD * pSubFld   - Ptr to subfield
  978.  *
  979.  *    Returns:      CHAR8 *                 - Name of subfield
  980.  *
  981.  * ---------------------------------------------------------------------- */
  982.  
  983. LPSTR GetSubFldName( JAMSUBFIELD FAR * pSubFld )
  984. {
  985.   int     i;
  986.  
  987.   for( i = 0; i < sizeof( SubFieldInfo ) / sizeof( SubFieldInfo [0] ); i++ )
  988.     {
  989.     if( pSubFld->LoID == SubFieldInfo [i].LoID &&
  990.         pSubFld->HiID == SubFieldInfo [i].HiID )
  991.       return( SubFieldInfo [i].pName );
  992.     }
  993.  
  994.   return( "Undefined" );
  995. }
  996.  
  997.  
  998. /* ---------------------------------------------------------------------- *
  999.  *
  1000.  *  GetSubFldStr
  1001.  *
  1002.  *    Convert the subfield contents to a string that can be displayed
  1003.  *
  1004.  *    Parameters:   JAMSUBFIELD * pSubFld   - Ptr to subfield
  1005.  *
  1006.  *    Returns:      CHAR8 *                 - Ptr to buffer containing
  1007.  *                                            subfield contents
  1008.  *
  1009.  * ---------------------------------------------------------------------- */
  1010.  
  1011. LPSTR GetSubFldStr( JAMSUBFIELD FAR * pSubFld )
  1012. {
  1013.   static UCHAR8   Buffer [256],
  1014.                 * pBuf;
  1015.   UINT32          i;
  1016.   int             BufPos;
  1017.  
  1018.   for(  pBuf = Buffer, i = BufPos = 0;
  1019.         i < pSubFld->DatLen && BufPos + 5 < sizeof( Buffer );
  1020.         pBuf++, i++, BufPos++ )
  1021.     {
  1022.     if(( UCHAR8 ) *((UCHAR8 _JAMFAR *) JAMsysAddFarPtr ( pSubFld->Buffer, i )) < ' ' )
  1023.       {
  1024.       wsprintf(( LPSTR ) pBuf, "<%02x>", ( UCHAR8 ) *((UCHAR8 _JAMFAR *) JAMsysAddFarPtr ( pSubFld->Buffer, i )) );
  1025.       BufPos += 3;
  1026.       pBuf += 3;
  1027.       }
  1028.     else
  1029.       *pBuf = *((UCHAR8 _JAMFAR *) JAMsysAddFarPtr ( pSubFld->Buffer, i ));
  1030.     }
  1031.  
  1032.   *pBuf = '\0';
  1033.  
  1034.   OemToAnsi(( LPSTR ) Buffer, ( LPSTR ) Buffer );
  1035.  
  1036.   return(( LPSTR ) Buffer );
  1037. }
  1038. #if defined (__BORLANDC__)
  1039. #pragma warn .par
  1040. #endif
  1041.  
  1042.  
  1043. /* end of file "jamutilw.c" */
  1044.